# -*- coding:utf-8 -*-

import os, sys
from loguru import logger

MODULE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
print('MODULE_PATH:{}'.format(MODULE_PATH))
if MODULE_PATH not in sys.path:
    sys.path.append(MODULE_PATH)

# 项目路径下创建log目录保存日志文件
log_path = '../log/'  # 拼接指定路径

# 判断目录是否存在，不存在则创建新的目录
if not os.path.isdir(log_path):
    os.makedirs(log_path)

logger.add(os.path.join(log_path, "logger-info-{time:YYYY-MM-DD}.log"),
           filter=lambda x: 'INFO' in str(x['level']).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="INFO",
           rotation='100 MB',
           retention='10 days',
           enqueue=True)

logger.add(os.path.join(log_path, "logger-error-{time:YYYY-MM-DD}.log"),
           filter=lambda x: 'ERROR' in str(x['level']).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="ERROR",
           rotation='100 MB',
           retention='10 days',
           enqueue=True)

logger.add(os.path.join(log_path, "logger-debug-{time:YYYY-MM-DD}.log"),
           filter=lambda x: 'DEBUG' in str(x['level']).upper(),
           format="{time:YYYY-MM-DD at HH:mm:ss} | {level} | {message}",
           level="DEBUG",
           rotation='100 MB',
           retention='10 days',
           enqueue=True)